<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:include href="/content/xsl/comments/comment.xsl" />
  <xsl:include href="/content/xsl/posts/add.xsl" />
  <xsl:include href="/content/xsl/main.xsl" />

  <xsl:template match="content">
    <xsl:apply-templates select="post" />
    <input type='hidden' id='content-scripts' value='post.js' />
  </xsl:template>

  <xsl:template match="post">
    <div class='post' data-post-id='{@id}'>
      <p class='signature'>
        <span title='Дата публикации'>
          <span class='ui-icon ui-icon-calendar' /><xsl:value-of select="@date" />
        </span>
        <xsl:apply-templates select="autor" />
      </p>
      <xsl:if test="@can-edit=1">
        <p>
          <span class='ui-icon ui-icon-pencil' />&#160;<a href='#' id='update-post'>Править</a>
          <span class='ui-icon ui-icon-trash' />&#160;<a href='#' class='del-post'>Удалить</a>
        </p>
        <xsl:call-template name="form">
          <xsl:with-param name="action">update</xsl:with-param>
        </xsl:call-template>
      </xsl:if>
      <div>
        <h2>
          <xsl:value-of select="title" />
        </h2>
        <xsl:apply-templates select="illustrations" />
        <div class='text'>
          <xsl:value-of select="content" disable-output-escaping="yes" />
        </div>
        <br />
        <xsl:if test="//auth and (//auth/@id!=autor/@id) and (@score='')">
          <div>
            <xsl:call-template name="vote" />
          </div>
        </xsl:if>
        <xsl:apply-templates select="tags" />
      </div>
      <div class='wrapper services'>
        <div class='service'>
          <a href='http://twitter.com/share?text=%t%&#38;url=%u%' id='twitter' title='Добавить в Twitter' data-getcount='http://urls.api.twitter.com/1/urls/count.json?url=%u%&#38;callback' data-count='.count' />
        </div>
        <div class='service'>
          <a href='http://google.com/buzz/post?url=%u%&#38;imageurl=%i%' id='googlebuzz' title='Отправить в Живую ленту Google' data-getcount='http://www.google.com/buzz/api/buzzThis/buzzCounter?url=%u%&#38;callback' data-count='[url]' />
        </div>
        <div class='service'>
          <a href='http://vkontakte.ru/share.php?url=%u%&#38;image=%i%' id='vkontakte' title='Поделиться В Контакте' data-getcount='http://vkontakte.ru/share.php?act=count&#38;index=1&#38;url=%u%&#38;callback' />
        </div>
        <div class='service'>
          <a href='http://facebook.com/sharer.php?u=%u%' id='facebook' title='Поделиться в Facebook' data-getcount='https://api.facebook.com/method/fql.query?query=select total_count from link_stat where url=="%u%"&#38;format=json&#38;callback' data-count='[0].total_count' />
        </div>
        <div class='service'>
          <a href='http://connect.mail.ru/share?share_url=%u%&#38;imageurl=%i%' id='myworld' title='Поделиться в Моем Мире' data-getcount='http://connect.mail.ru/share_count?url_list=%u%&#38;callback=1&#38;func' data-count='[url].shares' />
        </div>
        <div class='service'>
          <a href='http://livejournal.com/update.bml?subject=%t%&#38;event=%u%' id='livejournal' title='Опубликовать в Live Journal' />
        </div>
      </div>
      <h3 id='comments'>
        <span class='icon' />
        <span class='counter'>Комментарии&#160;(<label><xsl:value-of select="count(//comment)" /></label>)</span>
      </h3>
      <xsl:choose>
        <xsl:when test="//auth">
          <p id='add-comment' data-table='posts' data-rec-id='{@id}'>
            <span class='ui-icon ui-icon-comment' />&#160;<a href='#' class='add-comment'>Оставить комментарий</a>
          </p>
          <div class='invisible' id='comment'><textarea /></div>
        </xsl:when>
        <xsl:otherwise>
          <p class='errorMessage'>
            Оставлять комментарии могут только зарегистрированные пользователи
          </p>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:apply-templates select="comments" />
    </div>
    <div id='vk-discussion' data-post-id='{@id}'>
      <div id='vk_like' />
      <br />
      <div id='vk_comments' />
    </div>
  </xsl:template>

  <xsl:template match="illustrations">
    <div id='illustrations' data-main-img='{@main}'>
      <xsl:apply-templates select="illustration" />
    </div>
  </xsl:template>

  <xsl:template match="illustration">
    <div class='ui-state-default illustration'>
      <a href='{//urls/base}/content/img/illustrations/{.}' title='{../../title}' rel='photos{../../@id}'>
        <img src='{//urls/base}/content/thumb/illustrations/{.}?s=96' />
      </a>
    </div>
    <xsl:if test="position()!=last()">&#160;</xsl:if>
  </xsl:template>

  <xsl:template match="comments">
    <div class='comments'>
      <xsl:apply-templates select="comment" />
    </div>
  </xsl:template>

</xsl:stylesheet>
